package com.sunmi.usercenter;

import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler;

import com.sunmi.usercenter.utils.FileUtils;

import android.app.Application;
import android.util.Log;

public class MyApplication extends Application {

	protected static final String TAG = "MyApplication";

	@Override
	public void onCreate() {
		super.onCreate();
		configUncaughtExceptionHandler();
	}

	/** 捕获异常 */
	private void configUncaughtExceptionHandler() {
		Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

			@Override
			public void uncaughtException(Thread thread, Throwable ex) {
				Log.e(TAG, "uncaughtException crash", ex);
				try {
					ex.printStackTrace(new PrintStream(FileUtils.createErrorFile()));
				} catch (FileNotFoundException e) {
					Log.e(TAG, "创建异常文件失败");
					e.printStackTrace();
				}
			}

		});
	}
}
